﻿module Sustainalytics.Security.Login {
    import Auth = Sustainalytics.Authentication;

    export class LegalAgreementController {
        constructor(
            private $q: ng.IQService,
            private $scope: ngScope,
            private $modalInstance: Common.IModalInstance,
            private AuthenticationService: Auth.IAuthenticationService,
            private username: string) {
            var ctx = this;

            $scope['legalAgreement'] = this;
        }

        public accept() {
            var ctx = this;

            ctx.AuthenticationService.acceptLegalAgreement(ctx.username)
                .success(() => {
                    ctx.$modalInstance.close(true);
                })
                .error(function () {
                    ctx.$modalInstance.dismiss(arguments);
                });
        }

        public cancel() {
            this.$modalInstance.close(false);
        }
    }

    export var controllerName = 'LegalAgreementController';

    angular.module(securityLoginModuleName).controller(controllerName, [
        '$q', '$scope', '$modalInstance', 'AuthenticationService', 'username', LegalAgreementController]);
}
